﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace lesson1
{
    public partial class Form1 : Form
    { 
        List<Point> points = new List<Point>();
        enum drawTypeEnum
        {
            None,
            DDA,
            Bresenham,
            MidCircle,
            BresenhamCircle,
            CubicSpline
        }
        drawTypeEnum currentDrawType = drawTypeEnum.None;
        public Form1()
        {
            InitializeComponent();

        }

        private void dDAToolStripMenuItem_Click(object sender, EventArgs e)
        {
            currentDrawType = drawTypeEnum.DDA;
        }

        private void panel1_MouseDown(object sender, MouseEventArgs e)
        {
            switch (currentDrawType)
            {
                case drawTypeEnum.None:
                    break;
                case drawTypeEnum.DDA:
                    points.Add(new Point(e.X, e.Y));
                    if (points.Count == 2)
                    {
                        MyGDIClass.DDA(panel1.CreateGraphics().GetHdc(), points[0].X, points[0].Y, points[1].X, points[1].Y);
                        points.Clear();
                    }
                    break;
                case drawTypeEnum.Bresenham:
                    points.Add(new Point(e.X, e.Y));
                    if (points.Count == 2)
                    {
                        MyGDIClass.Bresenham(panel1.CreateGraphics().GetHdc(), points[0].X, points[0].Y, points[1].X, points[1].Y);
                        points.Clear();
                    }
                    break;
                case drawTypeEnum.MidCircle:
                case drawTypeEnum.BresenhamCircle:
                    points.Add(new Point(e.X, e.Y));
                    break;
                case drawTypeEnum.CubicSpline:
                    points.Add(new Point(e.X, e.Y));
                    break;
                default:
                    break;
            }

        }
        private void midCircleToolStripMenuItem_Click(object sender, EventArgs e)
        {
            currentDrawType = drawTypeEnum.MidCircle;
        }

        private void panel1_MouseUp(object sender, MouseEventArgs e)
        {
            int dis;
            switch (currentDrawType)
            {
                case drawTypeEnum.None:
                    break;
                case drawTypeEnum.DDA:
                    break;
                case drawTypeEnum.Bresenham:
                    break;
                case drawTypeEnum.MidCircle:
                    dis = (int)Math.Sqrt((e.X - points[0].X) * (e.X - points[0].X) + (e.Y - points[0].Y) * (e.Y - points[0].Y));
                    MyGDIClass.MidCircle(panel1.CreateGraphics().GetHdc(), points[0].X, points[0].Y, dis);
                    points.Clear();
                    break;
                case drawTypeEnum.BresenhamCircle:
                    dis = (int)Math.Sqrt((e.X - points[0].X) * (e.X - points[0].X) + (e.Y - points[0].Y) * (e.Y - points[0].Y));
                    MyGDIClass.BresenhamCircle(panel1.CreateGraphics().GetHdc(), points[0].X, points[0].Y, dis);
                    points.Clear();
                    break;
                default:
                    break;
            }
        }
        private void 清除ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Refresh();
        }

        private void bresenhamToolStripMenuItem_Click(object sender, EventArgs e)
        {
            currentDrawType = drawTypeEnum.Bresenham;
        }

        private void bresenhamCircleToolStripMenuItem_Click(object sender, EventArgs e)
        {
            currentDrawType = drawTypeEnum.BresenhamCircle;
        }

        private void cubicSplineToolStripMenuItem_Click(object sender, EventArgs e)
        {
            currentDrawType = drawTypeEnum.CubicSpline;
        }

        private void panel1_DoubleClick(object sender, EventArgs e)
        {
            switch (currentDrawType)
            {
                case drawTypeEnum.None:
                    break;
                case drawTypeEnum.DDA:
                    break;
                case drawTypeEnum.Bresenham:
                    break;
                case drawTypeEnum.MidCircle:
                    break;
                case drawTypeEnum.BresenhamCircle:
                    break;
                case drawTypeEnum.CubicSpline:
                    points.RemoveAt(points.Count - 1);
                    MyGDIClass.CubicSpline(panel1.CreateGraphics().GetHdc(), points);
                    points.Clear();
                    break;
                default:
                    break;
            }
        }
    }
}
